'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../../common/component');
var utils_1 = require('../../common/utils');
component_1.VantComponent({
  classes: ['title-class'],
  props: {
    title: String,
    fixed: {
      type: Boolean,
      observer: 'setHeight',
    },
    placeholder: {
      type: Boolean,
      observer: 'setHeight',
    },
    leftText: String,
    rightText: String,
    customStyle: String,
    customtitleStyle: String,
    leftArrow: Boolean,
    border: {
      type: Boolean,
      value: true,
    },
    zIndex: {
      type: Number,
      value: 1,
    },
    safeAreaInsetTop: {
      type: Boolean,
      value: true,
    },
    capsuleStyle: String,  //左边按钮
    noredirect:{
      type: Boolean,
      value: false,
    },
    mode: {
      type: String,
      value: "auto",  //auto home goback
    },
    backlink:{
      type: String,
      value: '',
    },
    customNavStyle:{
      type: String,
      value: '',
    }
  },
  data: {
    statusBarHeight: 0,
    height: 44,
    baseStyle: '',
    plen: 0,
    capsuleData :{ count: 0, showhome: false, showblack: false }
  },
  created: function () {
    var statusBarHeight = utils_1.getSystemInfoSync().statusBarHeight;
    var _a = this.data,
      safeAreaInsetTop = _a.safeAreaInsetTop,
      zIndex = _a.zIndex;
    var paddingTop = safeAreaInsetTop ? statusBarHeight : 0;
    var baseStyle =
      'z-index: ' + zIndex + ';padding-top: ' + paddingTop + 'px;';
      let capsule = wx.getMenuButtonBoundingClientRect(); 
      var titlecss= "height:"+capsule.height+"px;line-height:"+capsule.height+"px";   
      var  capsulestyle="height:"+capsule.height+"px;"+this.data.capsulestyle;
    this.setData({
      statusBarHeight: statusBarHeight,
      height: 44 + statusBarHeight,
      baseStyle: baseStyle,
      titlecss:titlecss,
      capsulestyle:capsulestyle
    });
  },
  mounted: function () {
    this.setHeight();
    this.calculatecapsule()
  },
  methods: {
    goback(){
      if(this.data.backlink){
          wx.redirectTo({
            url:this.data.backlink,
          })
      }
      else
      {
        if(this.data.noredirect){
                this.onClickLeft()
        }
        else
        {
          wx.navigateBack({
            delta: 1
          })
        }
     
      }
     
    },
    gohome(){
      var app =getApp();
      var url="/xc_lshop/index/index"
      if(app.globalData.configdata && app.globalData.configdata["basic"]["homeurl"]){
        url=app.globalData.configdata["basic"]["homeurl"];
      }
      wx.reLaunch({url:url});
     },
    calculatecapsule: function () {

      var $_pages = getCurrentPages()
      var plen = $_pages.length;
      this.setData({ plen: plen })

      var capsuleData = { count: 0, showhome: false, showblack: false }
      if (this.data.mode == "auto") {
        if (this.data.plen > 1) {

          
          capsuleData.count++;
          capsuleData.showblack = true;
        }
        capsuleData.count++;
        capsuleData.showhome = true;
      } else if (this.data.mode == "home") {
        capsuleData.count++;
        capsuleData.showhome = true;
      } else if (this.data.mode == "black") {
        capsuleData.count++;
        capsuleData.showhome = true;
      }
      this.setData({capsuleData:capsuleData})

    },
    onClickLeft: function () {
      this.$emit('click-left');
    },
    onClickRight: function () {
      this.$emit('click-right');
    },
    setHeight: function () {
      var _this = this;
      if (!this.data.fixed || !this.data.placeholder) {
        return;
      }


      return ;
      wx.nextTick(function () {
        _this.getRect('.van-nav-bar').then(function (res) {


          _this.setData({ height: res.height });
        });
      });
    },
  },
});
